<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>

    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>

    <style>
        .adminInfo{
            position: relative;
            left:33%;
            font-size: 18px;
            padding-top: 5%;
        }
        .row{
            padding-bottom: 20px;
        }
        label{
            font-weight: normal;
        }
        span{
            color: #0b6cbc;
        }
        #confirm{
            position: relative;
            top:0px;
            left:90px;
        }
        #cancel{
            position: relative;
            top:0px;
            left:125px;
        }
    </style>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">修改信息</strong>
            <small></small>
        </div>
    </div>

    <hr>

    <div class="am-g">
        <form class="adminInfo">
            <div class="row">
                <label>用户名称：</label><input type="text" id="name" disabled></input>
            </div>

<!--            <div class="row">-->
<!--                <label>账户类型：</label><input type="text" id="type" disabled></input>-->
<!--            </div>-->

            <div class="row">
                <label>邮箱地址：</label><input type="text" id="email"></input>
            </div>

            <div class="row">
                <label>手机号码：</label><input type="text" id="phone"></input>
            </div>

            <div class="row">
                <div>
                    <a class="am-btn am-btn-primary" onclick="confirm()" id="confirm">确认</a>
                    <a class="am-btn am-btn-primary" onclick="cancel()" id="cancel">取消</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    //id从url得到
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];

    $(function(){
        $.ajax({
            type: 'post',
            url: '/admin/getInfo',
            data: {id:uid},
            dataType: 'json',
            success: function (mydata) {
                document.getElementById("name").value=mydata.name;
                document.getElementById("email").value=mydata.email;
                document.getElementById("phone").value=mydata.phone;
            },
            error: function () {
                alert("error");
            }
        })
    })

    function confirm() {
        var email=document.getElementById("email").value;
        var phone=document.getElementById("phone").value;
        $.ajax({
            type: 'post',
            url: '/admin/updateInfo',
            data: {id:uid,email:email,phone:phone},
            dataType: 'text',
            success: function (mydata) {
                if(mydata=="true"){
                    alert("修改信息成功");
                    window.location.href="/adminInfo?uid=" + uid;
                }
                else{
                    alert("修改信息失败")
                }
            },
            error: function () {
                alert("修改信息失败");
            }
        })
    }

    function cancel() {
        window.location.href="/adminInfo?uid=" + uid;
    }

    //解析url传值
    function getParameter() {
        var url=location.search;//获取url?后面的内容
        var result=new Object();
        if(url.indexOf("?")!= -1){
            var str=url.substr(1);
            strs=str.split("&");
            for(var i=0;i<strs.length;i++){
                result[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</body>
</html>